/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package classPack;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 *
 * @author Eu
 */
public abstract class Classes implements Serializable {

    public static Object carregarString(String s) throws IOException, ClassNotFoundException {
        byte[] data = Base64Coder.decode(s);
        ObjectInputStream ois = new ObjectInputStream(
                new ByteArrayInputStream(data));
        Object o = ois.readObject();
        ois.close();
        return o;
    }

    public String gerarString() {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(this);
            oos.close();
            return new String(Base64Coder.encode(baos.toByteArray()));
        } catch (Exception e) {
        }
        return null;
    }
//    public abstract String gerarSaida();
//
//    public abstract void pegarSaida(String linhaArq);
//
//    public static void gravarArq(HashMap<String, Classes> listaGravar, String nomeArq) {
//        Encrypt meuEncrypt = Encrypt.getInstance();
//        BufferedWriter bw = null;
//        try {
//            bw = new BufferedWriter(new FileWriter(nomeArq));
//            for (Map.Entry<String, Classes> atualGravar : listaGravar.entrySet()) {
//                String chave = atualGravar.getKey();
//                Classes arqGravar = atualGravar.getValue();
//                bw.write(meuEncrypt.getEncryptMsg(arqGravar.gerarSaida(), Chave.getChaveLocal()));
//            }
//            bw.newLine();
//            bw.flush();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                bw.close();
//            } catch (IOException ex) {
//                ex.printStackTrace();
//            }
//        }
//    }
//
//    public void carregarArq(String nomeArq) {
//        Encrypt meuEncrypt = Encrypt.getInstance();
//        BufferedReader br = null;
//        try {
//            br = new BufferedReader(new FileReader(nomeArq));
//            String linha;
//
//            while ((linha = br.readLine()) != null) {
//                pegarSaida(meuEncrypt.getDecryptMsg(linha, Chave.getChaveLocal()));
//            }
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                br.close();
//            } catch (IOException ex) {
//                ex.printStackTrace();
//            }
//        }
//    }
}
